<template>
  <el-form-item :label="label">
    <el-select
      :value="value"
      :placeholder="placeholder"
      @change="changeHandler"
    >
      <el-option
        v-for="item in data"
        :key="item.key"
        :value="item.value"
        :label="item.key"
      />
    </el-select>
  </el-form-item>
</template>

<script>
import { getDictionary } from '@/api/common'
export default {
  name: 'Dictionary',
  model: {
    prop: 'value',
    event: 'change'
  },
  props: {
    value: {
      type: Number,
      default: null
    },
    code: {
      type: String,
      default: ''
    },
    label: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      data: [],
      placeholder: `请选择${this.label}`
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      getDictionary({ code: this.code }).then((r) => {
        console.log(this.code)
        this.data = r.data
      })
    },
    changeHandler(value) {
      this.$emit('change', value)
    }
  }
}
</script>

<style>
</style>
